import {Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {NavigationService} from '../navigation.service';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    selector: 'app-list',
    templateUrl: './list.component.html',
})
export class ListComponent implements OnInit {
    data: any[] = [];

    constructor(private msg: NzMessageService,
                private navigationService: NavigationService, ) {
    }

    ngOnInit() {
        this.getList();
    }

    /**
     * 获取菜单列表
     */
    getList() {
        this.navigationService.getNavigationList().subscribe(res => {
            this.data = res['list'];
        });
    }

    /**
     * 删除菜单
     * @param navigation
     */
    delNavigation(navigation) {
        const index = this.data.indexOf(navigation);
        this.data = [...this.data.slice(0, index), ...this.data.slice(index + 1, this.data.length)];
        this.navigationService.delNavigation(navigation.id).subscribe(res => {
            this.msg.success('删除成功');
            this.getList();
        }, __ => {
            this.getList();
        });
    }
}
